﻿using System;
using Caliburn.Micro;

namespace Scrabble.Tasks
{
    public class DelegatedTask : IResult
    {
        private readonly Func<bool> _task;

        public event EventHandler<ResultCompletionEventArgs> Completed;

        public DelegatedTask(Func<bool> task)
        {
            _task = task;
        }
    
        public void  Execute(ActionExecutionContext context)
        {
            Completed(this, new ResultCompletionEventArgs { WasCancelled = _task == null || ! _task() });
        }
    }
}